use std::sync::Mutex;
use tauri::{AppHandle, State};

use crate::{
    model::{AppState, Config},
    utils::get_config_file,
};
#[tauri::command]
pub fn save_settings(
    state: State<'_, Mutex<AppState>>,
    app: AppHandle,
    configs: Config,
) -> Result<(), String> {
    println!("{:?}", configs);
    let mut state = state.lock().expect("lock failed");
    state.configs = configs;
    let path = get_config_file(&app).expect("failed to get config file");
    state.configs.flush(path)
}

#[tauri::command]
pub fn load_settings(state: State<'_, Mutex<AppState>>) -> Result<Config, String> {
    let state = state.lock().expect("lock failed");

    Ok(state.configs.clone())
}
